﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JXT.PrimaryKey.Batman.Extensions
{
    /// <summary>
    /// 日期时间扩展类
    /// </summary>
    public static class DateTimeExtensions
    {
        /// <summary>
        /// 计算上一财务季度日期
        /// </summary>
        /// <param name="currentTime">计算基准时间</param>
        /// <returns>计算结果</returns>
        public static DateTime ToBeforeSeasonDate(this DateTime currentTime)
        {
            if (currentTime.Month > 3)
                return new DateTime(currentTime.Year, currentTime.Month - 3, DateTime.DaysInMonth(currentTime.Year, currentTime.Month - 3));
            else
                return new DateTime(currentTime.Year - 1, 12, 31);
        }

        /// <summary>
        /// 计算获取下一财务季度日期
        /// </summary>
        /// <param name="currentTime">计算基准时间</param>
        /// <returns>计算结果</returns>
        public static DateTime ToNextSeasonDate(DateTime currentTime)
        {
            if (currentTime.Month + 3 > 12)
                return new DateTime(currentTime.Year + 1, 3, 31);
            else
                return new DateTime(currentTime.Year, currentTime.Month + 3, DateTime.DaysInMonth(currentTime.Year, currentTime.Month + 3));
        }

        /// <summary>
        /// 获取与当前时间的时间差
        /// </summary>
        /// <param name="time">比较基准时间</param>
        /// <returns>计算时间差结果</returns>
        public static TimeSpan ToCurrentTimeSpan(this DateTime time)
        {
            return time - DateTime.Now;
        }
    }
}
